package com.atcumt.xiaoyuan;

public class HJ003 {
    public static void main(String[] args) {
        String str = new String("ABCDEFGH");
        char[] charArray = str.toCharArray();
        int n = 4;
        HJ003 hj003 = new HJ003();
        char[] res = hj003.solution(charArray, n);
        System.out.println(res);
    }

    // 设计一个函数，传入1个char数组，1个int值，返回从数字位置，左右颠倒后的字符串。比如传入ABCDEFGH，4，返回FGHABCDE。
    private static char[] solution(char[] chars, int n) {
        int len = chars.length;
        char[] res = new char[len];
        int j = 0;
        for (int i = n + 1; i <= len - 1; i++) {
            res[j++] = chars[i];
        }
        for (int i = 0; i <= n; i++) {
            res[j++] = chars[i];
        }
        return res;
    }
}
